Skip to content

feat(scheduler): add support for attemptDeadline in onSchedule #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Skyfury2651
Copy link

@Skyfury2651 Skyfury2651 commented Aug 19, 2025

Description

Add support for the attemptDeadline option in Cloud Scheduler when using Firebase Functions.

Previously, the attemptDeadline value had to be configured manually in the Google Cloud Console after deploying a scheduled function. With this change, developers can specify attemptDeadline directly in the onSchedule options ( or atleast i think so ), ensuring the configuration is applied automatically during deployment.

Code sample

export const myScheduledFunction = onSchedule({
  schedule: "0 9 * * *",
  attemptDeadline: "320s"
}, (event) => {
  // Your function code here
});


<!-- Proposing an API change? Provide code samples showing how the API will be used. -->

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @Skyfury2651, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the developer experience for Firebase Functions by integrating the attemptDeadline option directly into the onSchedule configuration. Previously, this setting required manual adjustment in the Google Cloud Console, but now it can be defined alongside other function parameters, streamlining deployment and configuration. The change primarily involves extending relevant interfaces and functions to properly handle and apply this new retry configuration option for both v1 and v2 Firebase Functions.

Highlights

  • New Feature: attemptDeadline Support: This pull request introduces support for the attemptDeadline option directly within the onSchedule configuration for Firebase Functions. This enhancement allows developers to specify the maximum duration for each job attempt programmatically, eliminating the need for manual configuration in the Google Cloud Console after deployment.
  • API Extension for Scheduler Options: The attemptDeadline property has been added to the ScheduleRetryConfig interface for v1 functions and the ScheduleOptions interface for v2 functions. This provides a consistent and integrated way to manage retry behavior for scheduled functions.
  • Enhanced Test Coverage: Comprehensive test cases have been added and updated across spec/runtime, spec/v1, and spec/v2 directories to ensure that the attemptDeadline option is correctly processed, recognized, and applied when defining scheduled Firebase Functions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the attemptDeadline option for scheduled functions, which is a great addition. The changes are well-implemented across the different layers of the codebase, including type definitions, v1 and v2 function configurations, and tests.

I've found one area in src/v2/providers/scheduler.ts where the logic can be simplified for better maintainability. My suggestion is to refactor the getOpts function to be more concise and avoid unnecessary checks.

Overall, this is a solid contribution. Once the suggested change is addressed, this should be ready to merge.

Comment on lines 64 to 81
const retryConfig: any = {
retryCount: args.retryCount,
maxRetrySeconds: args.maxRetrySeconds,
minBackoffSeconds: args.minBackoffSeconds,
maxBackoffSeconds: args.maxBackoffSeconds,
maxDoublings: args.maxDoublings,
};

if (args.attemptDeadline !== undefined) {
retryConfig.attemptDeadline = args.attemptDeadline;
}

return {
schedule: args.schedule,
timeZone: args.timeZone,
retryConfig: {
retryCount: args.retryCount,
maxRetrySeconds: args.maxRetrySeconds,
minBackoffSeconds: args.minBackoffSeconds,
maxBackoffSeconds: args.maxBackoffSeconds,
maxDoublings: args.maxDoublings,
},
retryConfig,
opts: args as options.GlobalOptions,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for constructing retryConfig can be simplified. The current implementation uses a temporary variable with type any and an if condition to add attemptDeadline.

Since copyIfPresent is used later in onSchedule and it already handles undefined values, you can simplify this by directly constructing the retryConfig object in the return statement. This will make the code more concise and improve type safety by avoiding any.

  return {
    schedule: args.schedule,
    timeZone: args.timeZone,
    retryConfig: {
      retryCount: args.retryCount,
      maxRetrySeconds: args.maxRetrySeconds,
      minBackoffSeconds: args.minBackoffSeconds,
      maxBackoffSeconds: args.maxBackoffSeconds,
      maxDoublings: args.maxDoublings,
      attemptDeadline: args.attemptDeadline,
    },
    opts: args as options.GlobalOptions,
  };

@Skyfury2651
Copy link
Author

This is my first contribution to this project 🙏
Please let me know if I misunderstood how attemptDeadline is applied, or if additional changes (tests, docs, etc.) are needed.

@Skyfury2651 Skyfury2651 marked this pull request as draft August 20, 2025 03:02
@Skyfury2651 Skyfury2651 marked this pull request as ready for review August 20, 2025 05:49
@Skyfury2651 Skyfury2651 marked this pull request as draft August 20, 2025 06:33
@Skyfury2651
Copy link
Author

Waiting for action on this PR :
firebase/firebase-tools#9007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant